<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>datajoin jQuery plugin test suite</title>
		<script type="text/javascript" src="./jsunity-0.6.js"></script>
		<script type="text/javascript" src="./djTest.js"></script>
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
		<script type="text/javascript" src="./jquery.datajoin.js"></script>
		<script type="text/javascript">
			
			jsUnity.attachAssertions();
			
			jsUnity.error = function (s) {
				   alert(s);
				};
				
			jsUnity.log = function (msg) {
				
				var style = msg.search('PASSED') === 1 ? ' style="background-color:#00FF00;" ' : 
					msg.search('FAILED') === 1 ? ' style="background-color:#FF0000;" ' : 
					msg.search('unning') === 1 ? ' style="font-weight:bold;margin-top:10px;"' : '';
				
				jq('#results').append('<div' + style + '>' + msg + '</div>');
				
			};
			
			var versions = {
				'1.2.3' : null,
				'1.2.6' : null,
				'1.3.0' : null,
				'1.3.1' : null,
				'1.3.2' : null,
				'1.4.0' : null,
				'1.4.1' : null,
				'1.4.2' : null,
				'1.4.3' : null,
				'1.4.4' : null,
				'1.5.0' : null
			};
			
			versions['1.5.0']=  jQuery.noConflict(true);
			
			jq = versions['1.5.0'];
			
			jq(document).ready(function(){

				function RunTest(jQuery){
					
						$ = jQuery;
						
						jq('#results').append('<div style="margin-top:10px;font-weight:bold;color:blue;font-size:1.1em;">jQuery Version : ' + $().jquery + '</div>');
					
						jsUnity.run(djTest);
				}
						
				jq.each(versions, function(key){
					
					jq('#versionmenu').append(jq('<option>' + key + '</option>'));
					
				});
				
				function LoadVersion( key, callback ) {
					
					if ( versions[key] !== null ) {
						
						callback(versions[key]);
						
					} else {
						
						jq.getScript('https://ajax.googleapis.com/ajax/libs/jquery/' +  key + '/jquery.min.js', function(data, textStatus){ 
					
							jq.getScript('jquery.datajoin.js', function(d, t){
								
								versions[key] = jQuery.noConflict(true);
						
								callback(versions[key]);
								
							});
							
						});
						
					}
					
				}
				

				function RunAll(select, index, length){
					
					LoadVersion( select.find('option:eq(' + index + ')').val(), function(){
						
						index++;
						
						if (index < length) {
							
							RunAll( select, index, length );
							
						} else {
							
							jq.each(versions, function (key){
							
								LoadVersion( key, RunTest );
						
							});
							
						}
						
					});
					
				}		
				
				jq('#versionmenu').change(function(){
					
					var select = jq('#versionmenu');
					
					var index = select.attr("selectedIndex");
					
					if (index == 1){
						
						jq('#results').html('');
						
						RunAll(select, 2, select.find('option').length);
						
					} else if ( index > 1) {
						
						jq('#results').html('');
						
						LoadVersion(select.val(), RunTest);
					}
					
				});
			});
			
		</script>
	
    </head>
    <body>
        <h1>datajoin jQuery Test Suite</h1>
		<select id="versionmenu">
			<option>Run test in jQuery version:</option>
			<option>All</option>
		</select>
		
		<div id="results"></div>
    </body>
</html>
